/**
 * Copyright (c) 2015-2017, Henry Yang 杨勇 (gismail@foxmail.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lambkit.component.shiro;

import com.jfinal.kit.PathKit;
import com.lambkit.core.config.annotation.PropertieConfig;

import java.io.File;

@PropertieConfig(prefix="lambkit.component.shiro")
public class ShiroConfig {

	public static final String TYPE_SERVER = "server";
    public static final String TYPE_CLIENT = "client";
    
    private boolean enable = false;
    private String filterType = "default";
    
    private String loginUrl = "/login";
    private String successUrl = "/";
    private String unauthorizedUrl = null;//"/error/403";
    private String shiroType = TYPE_SERVER;

    //filterType = default 模式下
    private String shiroIniFile = "shiro.ini";
    
    //filterType = lambkit 模式下
    private String configService="com.lambkit.module.upms.shiro.UpmsLambkitShiroConfigService";
    private String realm="com.lambkit.module.upms.shiro.UpmsRealm";
    private String cookieName = "lambkit-upms-server-session-id";
    private int sessionTimeout = 3600000;
    private int sessionValidationInterval = 600000;
    private boolean sessionValidationSchedulerEnabled = true;
    public boolean sessionIdCookieEnabled = true;
	public String rememberMeCookieName = "lambkit-upms";

    public String getLoginUrl() {
        return loginUrl;
    }

    public void setLoginUrl(String loginUrl) {
        this.loginUrl = loginUrl;
    }

    public String getSuccessUrl() {
        return successUrl;
    }

    public void setSuccessUrl(String successUrl) {
        this.successUrl = successUrl;
    }

    public String getUnauthorizedUrl() {
        return unauthorizedUrl;
    }

    public void setUnauthorizedUrl(String unauthorizedUrl) {
        this.unauthorizedUrl = unauthorizedUrl;
    }

    public String getShiroIniFile() {
        return shiroIniFile;
    }

    public void setShiroIniFile(String shiroIniFile) {
        this.shiroIniFile = shiroIniFile;
    }


    private Boolean config;

    public boolean isConfigOK() {
        if (config == null) {
            config = new File(PathKit.getRootClassPath(), shiroIniFile).exists();
        }
        return config;
    }

	public String getShiroType() {
		return shiroType;
	}

	public void setShiroType(String shiroType) {
		this.shiroType = shiroType;
	}

	public boolean isEnable() {
		return enable;
	}

	public void setEnable(boolean enable) {
		this.enable = enable;
	}

	public String getRealm() {
		return realm;
	}

	public void setRealm(String realm) {
		this.realm = realm;
	}

	public int getSessionTimeout() {
		return sessionTimeout;
	}

	public void setSessionTimeout(int sessionTimeout) {
		this.sessionTimeout = sessionTimeout;
	}

	public int getSessionValidationInterval() {
		return sessionValidationInterval;
	}

	public void setSessionValidationInterval(int sessionValidationInterval) {
		this.sessionValidationInterval = sessionValidationInterval;
	}

	public boolean isSessionValidationSchedulerEnabled() {
		return sessionValidationSchedulerEnabled;
	}

	public void setSessionValidationSchedulerEnabled(boolean sessionValidationSchedulerEnabled) {
		this.sessionValidationSchedulerEnabled = sessionValidationSchedulerEnabled;
	}

	public String getCookieName() {
		return cookieName;
	}

	public void setCookieName(String cookieName) {
		this.cookieName = cookieName;
	}
	
	public String getRememberMeCookieName() {
		return rememberMeCookieName;
	}
	
	public void setRememberMeCookieName(String rememberMeCookieName) {
		this.rememberMeCookieName = rememberMeCookieName;
	}
	
	public boolean isSessionIdCookieEnabled() {
		return sessionIdCookieEnabled;
	}
	
	public void setSessionIdCookieEnabled(boolean sessionIdCookieEnabled) {
		this.sessionIdCookieEnabled = sessionIdCookieEnabled;
	}

	public String getFilterType() {
		return filterType;
	}

	public void setFilterType(String filterType) {
		this.filterType = filterType;
	}

	public String getConfigService() {
		return configService;
	}

	public void setConfigService(String configService) {
		this.configService = configService;
	}
}



